package com.yuan.weike.model;

/**
 * 任务状态枚举
 */
public enum TaskStatusEnum {
    /**
     * 待处理
     */
    PENDING(0, "待处理"),

    /**
     * 进行中
     */
    IN_PROGRESS(1, "进行中"),

    /**
     * 已完成
     */
    COMPLETED(2, "已完成"),

    /**
     * 已关闭
     */
    CLOSED(3, "已关闭");

    private final int code;
    private final String description;

    TaskStatusEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据状态码获取枚举
     *
     * @param code 状态码
     * @return 对应的枚举值，如果找不到返回null
     */
    public static TaskStatusEnum fromCode(int code) {
        for (TaskStatusEnum status : TaskStatusEnum.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }
}